package cn.zhfeat.hatch.web.quartz;

import cn.zhfeat.core.core.SpringApplicationContextHolderUtil;
import cn.zhfeat.utils.cache.CacheUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
/**
 * @author ZhangHao
 * @version 1.0.0.1
 * @description: 短信通知定时任务
 * @date 2018/8/3 10:56
 */
@Component
public class Quartz {

    Logger log = LoggerFactory.getLogger(Quartz.class);

    private CacheUtility cacheUtility;

    private final String categoryKey = "Lock-Model";
    private final String cacheKey = "Lock-Name";
    private final String lockKey = "AemShareVisit-Task";	//锁用的一个key，4分钟失效的，所以每个任务执行时间间隔5分钟就可以


    /**
     * @description: 需求：每天九点，执行该定时器
     *               加定时器锁的目的是防止该项目在分布式环境下产生的调度问题
     *
     * @param
     *
     * @author ZhangHao
     * @date 2018/8/3 11:00
     * @version 1.0.0.1
     * @return void
     */

//	@Scheduled(cron = "0 0/5 * * * ?")
//    @Scheduled(cron = "0 0 9 * * ?")
    public void consumptionAemShareVisitSubmit() {
        String requestId = String.valueOf(System.nanoTime());
        cacheUtility = (CacheUtility) SpringApplicationContextHolderUtil.getSpringBean("cacheUtility");
        //锁有效期为一小时
        boolean isLock=cacheUtility.getCacheDataManager().lock(categoryKey, cacheKey, lockKey, 4, TimeUnit.MINUTES, requestId);
        if(!isLock) {
            return ;
        }

    }

}
